package com.leyou.item.web;


import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.BrandService;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController  {
    @Autowired
    private CategoryService categoryService;


    //根据父类的pid查询对应的分类集合
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByPid(@RequestParam("pid") Long pid){
        return ResponseEntity.ok(this.categoryService.queryCategoryByPid(pid));
    }


    // 根据分类id，查询商品分类
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> queryGoodsByGid(@PathVariable("id")Long id){
        return ResponseEntity.ok(this.categoryService.queryGoodsByGid(id));
    }

    //根据品牌id，查询商品分类的集合
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryByBrandId(@RequestParam("id") Long id){
        return ResponseEntity.ok(this.categoryService.queryByBrandId(id));
    }


    //根据分类id的集合，查询商品分类的集合
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryById(@RequestParam("ids") List<Long> ids){
        return ResponseEntity.ok(this.categoryService.queryCategoryById(ids));
    }

}
